const db = require('../model/db/dbhelper');
// 查询实例
const express = require('express');
const fs = require('fs');
const router = express.Router();
// const bcrypt = require('bcrypt')
/* GET home page. */
  // 插入数据
router.post('/swiper', function (req, res, next) {
	   //生成salt的迭代次数
 //    const saltRounds = 10;
 //    //随机生成salt
 //    const salt = bcrypt.genSaltSync(saltRounds);
 //    //获取hash值
 //    var hashName = bcrypt.hashSync(req.body.name, salt);

	// // req.body.name+'html'
	// // 文件路径
	let articlePath = `${__dirname}/../article/${req.body.name}.html`
	/**
	前端访问文章路径
	*/
	 catchphraseLink = `http://localhost:3000/article/${req.body.name}.html`
	fs.writeFile(articlePath, req.body.content, 'utf8',err => {
  if (err) {
   console.log(err);
  }
  console.log('文章已被保存');
});

    db.query(`INSERT INTO home_swiper(name,imgPath,catchphraseLink,bool) VALUES(?,?,?,?)`,
     [req.body.name,req.body.imgagePath,catchphraseLink,req.body.delivery], 
     function (result, fields) {
        console.log('查询结果：');

        res.send(result)
    })

    
});

module.exports = router;